<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title><style>
        .box{
            width: 400px;
            height: 200px;
            border: 1px solid red;
            margin: 30px auto;
            position: relative;
        }
        .box p{
            height: 30px;
            margin: 0px;
            background-color: aqua;
            width: 0px;
            line-height: 30px;
            text-align: center;
            color: rgb(176, 31, 31);
            position: absolute;
            top: 85px;
        }
    </style>
</head>
<body>
    <div class="box">
        <p></p>
    </div>
</body>
<script>
    const obox = document.querySelector('.box')
    const op = document.querySelector('.box p')

    let t;
    document.onclick=function(){
        clearInterval(t)
        t = setInterval(() => {
           
            if(op.offsetWidth===400){
                clearInterval(t);
                // op.innerHTML='100%'
            }else{
                op.style.width= op.offsetWidth +2 +'px';
                op.innerHTML= parseInt((op.offsetWidth/400)*100)+'%'
            }
        },30);
    }
</script>
</html>